﻿
using System;
namespace Model
{
	public interface AttributExpression
	{
		void EvaluateExpression(ref Attribut oldAttribut);
	}

	public class StringAttributExpression : AttributExpression
	{
		private string value;

		public StringAttributExpression(string newValue)
		{
			this.value = newValue;
		}

		public void EvaluateExpression(ref Attribut oldAttribut)
		{
			((StringAttribut)oldAttribut).Value = value;
		}
	}

	public class NumberAttributExpression : AttributExpression
	{
		private string operatorString;
		private double value;

		public NumberAttributExpression(string operatorString, double value)
		{
			this.value = value;
			this.operatorString = operatorString;
		}

		public void EvaluateExpression(ref Attribut oldAttribut)
		{
			switch (operatorString)
			{
				case "+":
					((NumberAttribut)oldAttribut).Value += value;
					break;
				case "-":
					((NumberAttribut)oldAttribut).Value -= value;
					break;
				case "*":
					((NumberAttribut)oldAttribut).Value *= value;
					break;
				case "/":
					((NumberAttribut)oldAttribut).Value /= value;
					break;
				case "=":
					((NumberAttribut)oldAttribut).Value = value;
					break;
				default:
					throw new ArgumentException("Der Operator '" + operatorString + "' existiert nicht.");
			}
		}
	}
}
